﻿
/*
*
*
* */
Rsd.createApplication({
    appTitle: '扬中住房专项维修资金管理系统V5.6',
    subTitle:'旗舰版',
    appName: 'Rsd.Faith',
    appFolder: 'src',
    //appHost: 'http://192.168.0.245/faith/',
    appHost: 'http://faith.redmicro.cn/',
    appHostIndex:'dev/index',
    loginUrl: 'login',
    indexUrl: 'index.html',
    assembelyName:'Rsd.Faith.Models',
    isDebug:false,
    isDemo:window.location.protocol == 'file:',
    appDate:new Date().getTime(),//
    requires: [],
    svg:'icon',
    beforeRun:function beforeRun() {

         Rsd.showWaiting(this.id);
         //Rsd.loadPlugin('./plugin/jquery/jquery-3.2.0.min.js');
         Rsd.loadPlugin('./plugin/jquery/jquery.md5.js');
         Rsd.loadScriptFile('./resources/storages/enums.js');
         //Rsd.alert("您当前使用的浏览器是：" + Rsd.detectNavigator());
         //Rsd.alert("您当前使用的操作系统是：" + Rsd.detectOS());
        Rsd.closeWaiting(this.id);
     },
    launch: function launch() {

        //alert("您当前使用的浏览器是：" + Rsd.detectNavigator());
        //alert("您当前使用的操作系统是：" + Rsd.detectOS());

        var me = this;
        //清楚所有缓存数据
        Rsd.clearSession();

        var _services = Rsd.create('Rsd.Faith.stores.ServicesStore',{});
        _services.load({},function (data) {

            if(Rsd.isEmpty(data.data.rows))
            {
                $msg('网络故障','服务加载失败,请检查网络或服务器是否正常。',[{text:'确定'},{text:'查看服务',fn:function () {
                        Rsd.redirect('http://faith.redmicro.cn/');
                        return false;
                    }}]);
            }
        });

        var _token = Rsd.getCookie("token");

        if(_token)
        {
            Rsd.setAppToken(_token);
            var ck_service = Rsd.app.getService('Verification.CheckSession');
            if(ck_service == null)
            {
                return true;
            }

            ck_service.requestJson( {
                //async:true,
                token: _token
            },function(_data){
                Rsd.closeWaiting(me.id);

                if (_data == null) {
                    Rsd.alert('请求验证失败，请联系管理员！');
                    return false;//后续方法不在执行
                 }
                return true;//后续方法继续执行
            });

        }
        else{
            var _login = Rsd.create('Rsd.Faith.views.LoginPage', {
                success: function (data) {

                    var _form = Rsd.create('Rsd.Faith.views.MainForm', {
                        requires: [
                            'Rsd.Faith.views.Footer',
                            'Rsd.Faith.views.Header',
                            'Rsd.Faith.views.MenuTree'
                        ],
                        border: false
                    });
                    Rsd.app.MainForm =_form;
                    Rsd.showPage = function(page) {_form.showPage(page);};
                    _form.show(1000).load();
                }

            });
            //window.alert = Rsd.alert;
            Rsd.closeWaiting(me.id);
            _login.showDialog(null,null,null,1000);
        }

    },
     /*

      * */
     showPage: function showPage(page,speed) {
         Rsd.app.MainForm.setPageTitle(page.title);
         Rsd.app.MainForm.showPage(page,speed);
     },

     /**
      * */
     showModelView:function(modeltype,formfields,record,title,btns,readOnly,parent) {

         var _type = modeltype;

         if(!Rsd.isEmpty(_type) && !_type.startWith('Rsd.'))
         {
             _type = Rsd.app.assembelyName + '.' + _type;
         }

         var _readOnly = (readOnly==undefined?false:readOnly);
         if(_readOnly || Rsd.isEmpty(_type))
         {
             var form = Rsd.create('Rsd.view.SingleDialog', {
                 modelType:_type,
                 fields:formfields,
                 title: title,
                 buttons:btns,
                 schema:null,
                 readOnly:_readOnly,
                 parent:parent||this
             });

             form.showDialog().load(record);
         }
         else
         {
             this.getSchema(_type,function (schema) {
                 var form = Rsd.create('Rsd.view.SingleDialog', {
                     modelType:_type,
                     fields:formfields,
                     title: title,
                     buttons:btns,
                     schema:schema,
                     readOnly:_readOnly,
                     parent:parent||this,
                     data:record
                 });

                 form.showDialog().load(record);
             });

         }

     },
    /*
     * */
     getSchemaListHandler:function loadSchemaListHandler(callback) {
         var me = this;

         var _service =  Rsd.app.getService('Dev.GetSchemaList');
         var _fn = function (data) {
             if(data.success)
             {
                 Rsd.callFunction(me,callback,[data.data.rows]);
             }
         }
         _service.requestJson({},_fn);
     },
     /*
     *
     * */
     getSchemaHandler:function getSchemaHandler(key, callback) {
         var me = this;
         var _fn = function (data) {

             if(data.success)
             {
                 var _schema = Rsd.create('Rsd.data.Schema',{
                     name:data.data.modelType,
                     text:'',
                     keys:data.data.key.split(','),
                     columns:data.data.gridColumns,
                     fields:data.data.formFields,
                     insertService:'Biz.Save',
                     updateService:'Biz.Save',
                     deleteService:'Biz.Delete',
                     findService:'Biz.GetObject',
                     getService:'Biz.GetList'
                 });
                 Rsd.callFunction(me,callback,[_schema]);
             }else
                 {
                     alert(data.message||data.msg||'获取Schema失败！');
                 }

         }
         Rsd.create('Rsd.Faith.stores.SchemaStore',{}).getSchema(key, _fn)
     }
});

